package base64

import "encoding/base64"

func NewBase64Url(src []byte) *Data {
	encode := Data(base64.URLEncoding.EncodeToString(src))
	return &encode
}

func NewBase64UrlFromString(src string) *Data {
	encode := Data(base64.URLEncoding.EncodeToString([]byte(src)))
	return &encode
}

//base64编码
type DataUrl string

func (d *DataUrl) Decode() (string, error) {
	de, err := base64.URLEncoding.DecodeString(string(*d))
	if err != nil {
		return "", err
	}
	return string(de), nil
}

func (d *DataUrl) DecodeByte() ([]byte, error) {
	de, err := base64.URLEncoding.DecodeString(string(*d))
	if err != nil {
		return nil, err
	}
	return de, nil
}

func (d DataUrl) String() string {
	return string(d)
}
